<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('物资仓储存列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            物资名称：<input name="meterialName" onclick="selectMeterialTree()" id="treeName" readonly="true" type="text"
                                        placeholder="请选择">

                        </li>


                        <!--<li>
                         <div class="form-group">
                             <label class="col-sm-1 control-label" >物资名称：</label>
                             <div class="col-sm-1">
                                 <div class="input-group">
                                     <input name="meterialName" onclick="selectMeterialTree()" id="treeName" type="text" placeholder="请选择" class="form-control" required>
                                     <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                 </div>
                             </div>
                         </div>
                        </li>-->
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>

                        <li>
                            采购人：<input type="text" name="purchaserName"/>
                        </li>

                        <li>
                            入库人：<input type="text" name="createByName"/>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncGoods:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:ncGoods:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:ncGoods:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:user:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
    <div class="bottom-btns"></div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncGoods:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncGoods:remove')}]];
    var depotFlag = [[${@permission.hasPermi('system:ncGoods:depot')}]];
    var prefix = ctx + "system/ncGoods";

    $(function () {
        var datass = [[${@dict.getType('material_unit')}]];
        var options = {
            uniqueId: "goodsId",
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "物资仓储存",
            showExport: true,
            sortName:'validDate',
            sortOrder:'desc',
            columns: [{
                checkbox: true
            }, {
                title: "序号",
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
                {
                    field: 'goodsId',
                    title: '物资id',
                    visible: false
                },
                {
                    field: 'goodsCode',
                    title: '物资批次',
                    sortable: true
                },
                {
                    field: 'meterialName',
                    title: '物资名称',
                    sortable: true,
                },
                /*                {
                                    field: 'meterialId',
                                    title: '物资编号',
                                    sortable: true
                                },*/
                {
                    field: 'stockAmout',
                    title: '库存',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value /*+ $.table.selectDictLabel(datass,row.unit)*/ ;
                        }
                    }
                },
                {
                    field: 'unit',
                    title: '单位',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return $.table.selectDictLabel(datass,row.unit) ;
                        }
                    }
                },
                {
                    field: 'inputAmount',
                    title: '入库数量',
                },
                {
                    field: 'validDate',
                    title: '有效期',
                    sortable: true
                },
                {
                    field: 'purchaserName',
                    title: '采购人'
                },
                {
                    field: 'createByName',
                    title: '入库人'
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('&nbsp;<a class="btn btn-info btn-xs ' + depotFlag + '" href="javascript:void(0)" onclick="depot(\'' + row.goodsId + '\')"><i class="fa fa-key"></i>出库</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        var btns = [{
            name: '工作记录',
            url: ctx + 'system/ncNormalWorks?workType=12',
            id: 'normal-work'
        },
            {
                name: "出库记录",
                url: ctx + 'system/ncGoodsLog',
                id: 'Depot-work'
            }]
        addBtns(btns);


    });


    /* 出库操作 */
    function depot(goodsId) {
        var url = prefix + '/depot/' + goodsId;
        $.modal.open("出库", url);
    }


    //物资选择树
    function selectMeterialTree() {
        var treeId = $("#treeId").val();
        var meterialId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/meterial/selectMeterialTree/" + meterialId;
        var options = {
            title: '物资选择',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }
    setTitle("物资管理",false)

</script>
</body>
</html>